package com.cnswhy.cloud.server.core.wallet.impl;

import com.alibaba.fastjson.JSON;
import com.cnswhy.cloud.common.core.utils.SystemClockUtil;
import com.cnswhy.cloud.server.common.entity.enumeration.TransType;
import com.cnswhy.cloud.server.core.entity.WalletTransDtl;
import com.cnswhy.cloud.server.core.service.WalletTransDtlService;
import com.cnswhy.cloud.server.core.wallet.WalletDtlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;

@Slf4j
@Service
public class WalletDtlServiceImpl implements WalletDtlService {
    @Autowired
    WalletTransDtlService walletTransDtlService;
    @Override
    public WalletTransDtl addWalletTransDtl(Long customerWalletId,Long customerId, TransType transType,String transOrderId,Long beginBal,Long dedBal) {
        WalletTransDtl walletTransDtl = new WalletTransDtl();
        walletTransDtl.setCustomerWalletId(customerWalletId);
        walletTransDtl.setTransType(transType);
        walletTransDtl.setTransOrderId(transOrderId);
        walletTransDtl.setBeginBal(beginBal);
        walletTransDtl.setDedBal(dedBal);
        walletTransDtl.setEndBal(beginBal + dedBal);
        walletTransDtl.setCustomerId(customerId);
        walletTransDtl.setSettDate(SystemClockUtil.getSettDateyyyyMMdd());
        walletTransDtlService.save(walletTransDtl);
        log.info("保存账户变动明细:{}", JSON.toJSONString(walletTransDtl));
        return walletTransDtl;
    }

    @Override
    public WalletTransDtl addWalletTransDtl(Long customerWalletId,Long customerId, TransType transType, String transOrderId, Long beginBal, Long dedBal, String spellorderId, String splitFrom,int splitLevel) {
        WalletTransDtl walletTransDtl = new WalletTransDtl();
        walletTransDtl.setCustomerWalletId(customerWalletId);
        walletTransDtl.setTransType(transType);
        walletTransDtl.setTransOrderId(transOrderId);
        walletTransDtl.setBeginBal(beginBal);
        walletTransDtl.setDedBal(dedBal);
        walletTransDtl.setEndBal(beginBal + dedBal);
        walletTransDtl.setSettDate(SystemClockUtil.getSettDateyyyyMMdd());
        walletTransDtl.setSpellOrderId(spellorderId);
        walletTransDtl.setSplitFrom(splitFrom);
        walletTransDtl.setSplitLevel(splitLevel);
        walletTransDtl.setCustomerId(customerId);
        walletTransDtlService.save(walletTransDtl);
        log.info("保存账户变动明细:{}", JSON.toJSONString(walletTransDtl));
        return walletTransDtl;
    }
}
